package edu.biwu.request;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.util.stream.Stream;

/**
 * HttpServletRequest中获取请求体的方法：
 *     public String getParameter(String name):适用于一个参数对应一个值，后端根据前端nanme的值获取对应的值
 *
 */
@WebServlet("/req/demo03")
public class RequestDemo03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //利用getParameter()获取参数对应的单一项
        System.out.println(request.getParameter("username"));
        System.out.println(request.getParameter("password"));
        System.out.println(request.getParameter("gender"));

        //2.利用getParameter()
        /*String[] hobbies = request.getParameterValues("hobby");
        for (String hobby : hobbies) {
            System.out.println(hobby);
        }*/
        Stream.of(request.getParameterValues("hobby")).forEach(System.out::println);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
